﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
/// <summary>
/// Summary description for AlbumsDAL
/// </summary>
public class AlbumsDAL: StandardConnectDB, IAlbums
{
	public AlbumsDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public List<Albums> GetListAlbumsOfUser(Users user)
    {

        List<Albums> ab = new List<Albums>();


        Dictionary<string, object> paramist = new Dictionary<string, object>();

        paramist.Add("@pUserName", user.Username);

        DataTable dt = this.DTExecuteSelect("spGetAblumofUser", paramist);


        foreach (DataRow dr in dt.Rows)
        {
            ab.Add(this.ConvertObjectDataRowToAlbum(dt.Rows[0]));
        }
         return ab;  
     
    
    
    }

    public Albums GetAlbumById(int idAlbum)
    {
        Albums ab = new Albums();

        Dictionary<string, object> paramist = new Dictionary<string, object>();
        paramist.Add("@pIdAlbum", idAlbum);

        DataTable dt = this.DTExecuteSelect("spGetAblumbyID", paramist);

        DataRow dr = dt.Rows[0];
        if (dt.Rows.Count == 1)
        {
            ab = this.ConvertObjectDataRowToAlbum(dr);
        }

        return ab;

    }

    public Albums GetAlbumByName(string name)
    {

        Albums ab = new Albums();

        Dictionary<string, object> paramist = new Dictionary<string, object>();

        paramist.Add("@pUserName", name);

         

        return ab;

    }

    public bool CreateAlbum(string name, string description, Users user)
    {
        throw new NotImplementedException();
    }

    public bool DeleteAlbum(Albums album)
    {
        throw new NotImplementedException();
    }

    public bool UpdateAlbum(Albums album)
    {
        throw new NotImplementedException();

    }
    
    public Albums ConvertObjectDataRowToAlbum(System.Data.DataRow dr)
    {

        Albums Al = new Albums();
        Al.IdAlbum = Convert.ToInt32(dr["IdAlbum"].ToString());
        Al.Name = dr["Names"].ToString();
        
        Al.Description = dr["Description"].ToString();
        Al.CreateTime = Convert.ToDateTime(dr["CreateTime"].ToString());
        String username = dr["UserName"].ToString();
        IUsers iUsers = new UsersDAL();
        Al.User = iUsers.GetUserByUsername(username);

        return Al;
    }
}